package com.bb.blog.code.zk;

import org.apache.zookeeper.*;
import org.apache.zookeeper.data.Stat;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.CyclicBarrier;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * zk链接测试
 */
public class ZkClient implements Watcher {
    public static final Logger logger = LoggerFactory.getLogger(ZkClient.class);
    protected CountDownLatch countDownLatch;
    protected   ZooKeeper zk;


    public ZkClient() {
        countDownLatch = new CountDownLatch(1);
        try {
            zk = new ZooKeeper("127.0.0.1:2181",2000,this);
            countDownLatch.await();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    @Override
    public void process(WatchedEvent watchedEvent) {
        logger.info(watchedEvent.toString());
        countDownLatch.countDown();
    }


}
